package config

import (
	"fmt"
	"time"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var DB *gorm.DB
var err error

type localTime struct {
	time.Time
}

func init() {

	fmt.Println("数据DB初始化", time.Now())
	// 初始化配置
	res := InitConfigDev()
	if res != nil {
		print(res)
	}

	dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local",
		Config.Database.Mysql.UserName,
		Config.Database.Mysql.Password,
		Config.Database.Mysql.Host,
		Config.Database.Mysql.Port,
		Config.Database.Mysql.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		//打印sql
		QueryFields: true,
		Logger:      logger.Default.LogMode(logger.Info),
		//SkipDefaultTransaction: true, //禁用事务
	})
	DB.Debug()
	if err != nil {
		fmt.Println(err)
	}
}
